/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.renderer;

import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Font;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.ListCellRenderer;
import edu.mobbuzz.bean.RSSChannel;
import edu.mobbuzz.util.theme.Theme;
import java.io.IOException;

/**
 *
 * @author irw
 */
public class RSSChannelRenderer extends Container implements ListCellRenderer{
    private Label rssSourceLbl = new Label("");
    private Label rssTitleLbl = new Label("");
    private Label rssDescriptionLbl = new Label("");
    private Label pic = new Label("");
    private Image icon = null;
    private Label focus = new Label("");
        
    public RSSChannelRenderer(){
        setLayout(new BorderLayout());
        addComponent(BorderLayout.WEST, pic);
        Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        rssSourceLbl.getStyle().setBgTransparency(0);  
       
        
        rssTitleLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL));
        rssTitleLbl.getStyle().setBgTransparency(0);
        rssTitleLbl.getStyle().setMargin(0, 0, 0, 0);
        
        rssSourceLbl.getStyle().setFont(Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
        rssSourceLbl.getStyle().setBgTransparency(0);
        rssSourceLbl.getStyle().setMargin(0, 0, 0, 0);
        
        rssDescriptionLbl.getStyle().setBgTransparency(0);  
        rssDescriptionLbl.getStyle().setFont(Theme.getFontDescriptionStyle("SansSerif"));
        rssDescriptionLbl.getStyle().setFgColor(0xFFFFFF);
        rssDescriptionLbl.getStyle().setMargin(0, 0, 0, 0);
        
        pic.getStyle().setBgTransparency(0);

        cnt.addComponent(rssTitleLbl);
        cnt.addComponent(rssSourceLbl);
        cnt.addComponent(rssDescriptionLbl);

        addComponent(BorderLayout.CENTER, cnt);
        focus.getStyle().setBgTransparency(100);
        focus.getStyle().setBgColor(0xCCCCCC);
    }
    
    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
        /*try {
            icon = Image.createImage("/icons/rss_channel.gif");
        } catch (IOException ex) {
            ex.printStackTrace();
        }*/

        RSSChannel rssChannel = (RSSChannel) value;
        rssTitleLbl.setText(rssChannel.getTitle());
        rssSourceLbl.setText(rssChannel.getSource());
        pic.setIcon(icon);
        return this;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }

}
